﻿/**************************************************
 *  Author :    youping
 *  CreateDate: 2019-12-16
 *  Title:      获取文件夹目录下的文件加名称
**************************************************/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Demo.FolderOp
{
    public partial class FolderOperator : Form
    {
        public FolderOperator()
        {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            string currentPath = this.txtPath.Text.Trim();
            string result = CommonMethod.IsPathUrlRight(currentPath);
            if (!string.IsNullOrWhiteSpace(result))
            {
                MessageBox.Show(result);
                return;
            }
            //第二种方法
            DirectoryInfo folder = new DirectoryInfo(currentPath);

            result = string.Empty;
            foreach (var myfolder in folder.GetDirectories())
            {
                result += myfolder.ToString() + "\r\n";
            }
            this.txtResult.Text = result;

            ////文件夹
            //foreach (FileInfo file in folder.GetFiles("*.txt"))
            //{
            //    Console.WriteLine(file.FullName);
            //}
        }

        private void btnFBD_Click(object sender, EventArgs e)
        {
            DialogResult dr = folderBrowserDialog.ShowDialog();
            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                this.txtPath.Text = folderBrowserDialog.SelectedPath;
            }
        }
    }
}
